{% extends 'base.html' %}

{% block title %}搜索结果 - 知疑{% endblock %}

{% block content %}
<div class="row">
    <!-- 主要内容区 -->
    <div class="col-md-8">
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h4>
                搜索结果
                {% if search_term %}
                <small class="text-muted">关键词: {{ search_term }}</small>
                {% endif %}
            </h4>
        </div>
        
        <div class="card">
            <div class="list-group list-group-flush">
                {% for question in questions.items %}
                <div class="list-group-item question-item">
                    <h5 class="question-title">
                        <a href="{{ url_for('question.detail', id=question.id) }}" class="text-decoration-none">
                            {{ question.title }}
                        </a>
                    </h5>
                    <div class="question-meta">
                        <span class="me-2">
                            <i class="fas fa-user me-1"></i>
                            <a href="{{ url_for('user.profile', username=question.author.username) }}" class="text-decoration-none">
                                {{ question.author.username }}
                            </a>
                        </span>
                        <span class="me-2">
                            <i class="fas fa-clock me-1"></i>{{ question.create_time.strftime('%Y-%m-%d') }}
                        </span>
                        <span class="me-2">
                            <i class="fas fa-comment me-1"></i>{{ question.answers.count() }} 回答
                        </span>
                        <span class="me-2">
                            <i class="fas fa-eye me-1"></i>{{ question.view_count }} 浏览
                        </span>
                    </div>
                    {% if question.tags.count() > 0 %}
                    <div class="mt-2">
                        {% for tag in question.tags %}
                        <a href="{{ url_for('main.tag', tag_id=tag.id) }}" class="tag tag-clickable">
                            {{ tag.name }}
                        </a>
                        {% endfor %}
                    </div>
                    {% endif %}
                </div>
                {% else %}
                <div class="list-group-item text-center py-5">
                    {% if search_term %}
                    <p class="text-muted mb-0">没有找到与"{{ search_term }}"相关的问题</p>
                    {% else %}
                    <p class="text-muted mb-0">请输入搜索关键词</p>
                    {% endif %}
                </div>
                {% endfor %}
            </div>
        </div>
        
        <!-- 分页 -->
        {% if questions.pages > 1 %}
        <nav aria-label="Page navigation" class="mt-4">
            <ul class="pagination justify-content-center">
                {% if questions.has_prev %}
                <li class="page-item">
                    <a class="page-link" href="{{ url_for('main.search', query=search_term, page=questions.prev_num) }}">
                        <i class="fas fa-chevron-left"></i>
                    </a>
                </li>
                {% else %}
                <li class="page-item disabled">
                    <span class="page-link"><i class="fas fa-chevron-left"></i></span>
                </li>
                {% endif %}
                
                {% for p in questions.iter_pages(left_edge=2, left_current=2, right_current=3, right_edge=2) %}
                    {% if p %}
                        {% if p == questions.page %}
                        <li class="page-item active">
                            <span class="page-link">{{ p }}</span>
                        </li>
                        {% else %}
                        <li class="page-item">
                            <a class="page-link" href="{{ url_for('main.search', query=search_term, page=p) }}">{{ p }}</a>
                        </li>
                        {% endif %}
                    {% else %}
                    <li class="page-item disabled">
                        <span class="page-link">...</span>
                    </li>
                    {% endif %}
                {% endfor %}
                
                {% if questions.has_next %}
                <li class="page-item">
                    <a class="page-link" href="{{ url_for('main.search', query=search_term, page=questions.next_num) }}">
                        <i class="fas fa-chevron-right"></i>
                    </a>
                </li>
                {% else %}
                <li class="page-item disabled">
                    <span class="page-link"><i class="fas fa-chevron-right"></i></span>
                </li>
                {% endif %}
            </ul>
        </nav>
        {% endif %}
    </div>
    
    <!-- 侧边栏 -->
    <div class="col-md-4">
        <!-- 热门问题 -->
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="mb-0"><i class="fas fa-fire me-2"></i>热门问题</h5>
            </div>
            <div class="list-group list-group-flush">
                {% for question in hot_questions %}
                <a href="{{ url_for('question.detail', id=question.id) }}" class="list-group-item list-group-item-action">
                    <div class="d-flex justify-content-between align-items-center">
                        <span class="text-truncate">{{ question.title }}</span>
                        <span class="badge bg-primary rounded-pill">{{ question.view_count }}</span>
                    </div>
                </a>
                {% else %}
                <div class="list-group-item text-center py-3">
                    <p class="text-muted mb-0">暂无热门问题</p>
                </div>
                {% endfor %}
            </div>
        </div>
        
        <!-- 标签云 -->
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0"><i class="fas fa-tags me-2"></i>热门标签</h5>
            </div>
            <div class="card-body">
                {% for tag in tags %}
                <a href="{{ url_for('main.tag', tag_id=tag.id) }}" class="tag tag-clickable">
                    {{ tag.name }}
                </a>
                {% else %}
                <p class="text-center text-muted mb-0">暂无标签</p>
                {% endfor %}
            </div>
        </div>
    </div>
</div>
{% endblock %} 